﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.TheResource;

namespace Ue.Qcdz.UI.Controls.TheResource
{
    public class ResourceEdit:SkinnedEntityEdit<Resource>
    {
        private TextBox tbxName;
        private TextBox tbxNum;
        private string sinkName = "~/Admin/Themes/Skins/Resources/ResourceEdit.ascx";
        #region Overrides of SkinnedControl

        protected override string GetSkinFileName()
        {
            return sinkName;
        }

        #endregion

        #region Overrides of SkinnedEntityEdit<Resource>

        protected override Resource Enttiy
        {
            get
            {
                if(this.Action=="Delete")
                {
                    return new Resource(this.EntityKey);
                }
                return new Resource
                    (
                    tbxName.GetValue<string>(),
                    tbxNum.GetValue<int>(),
                    (object)this.EntityKey
                    );
            }
            set
            {
                if(value==null)
                    return;
                tbxName.SetValue(value.Name);
                tbxNum.SetValue(value.Num);
            }
           
        }

        protected override void InitSkin(Control skin)
        {
            tbxName = skin.FindControl<TextBox>("tbxName");
            tbxNum = skin.FindControl<TextBox>("tbxNum");
        }

        #endregion
    }
}
